package snafu.implementation.actions.collect;

import java.util.List;

import snafu.framework.actions.AbstractAction;
import snafu.framework.actions.Intention;
import snafu.framework.objects.WorldObject;
import snafu.framework.objects.WorldObjectItself;
import snafu.framework.states.StateItself;
import snafu.framework.view.Access;
import snafu.framework.worlds.WorldMap;
import snafu.implementation.states.literals.have.HaveLiteralItself;
import snafu.implementation.states.literals.position.PositionLiteral;

/**
 *	An action representing the collection of an object. 
 */
public class CollectAction extends AbstractAction {

	/**
	 * Create the action.
	 * 
	 * @param targets
	 *            the target
	 * @param intention
	 *            the intention
	 */
	public CollectAction(List<WorldObject> targets, Intention<?> intention) {
		super(targets, intention);
	}

	@Override
	public void execute(WorldMap worldMap) {
		WorldObject target = targets.get(0);
		
		// get state
		StateItself agentState = (StateItself) agent.getState();
		StateItself targetState = (StateItself) target.getState();

		// add target to agent
		agentState.addLiteral(new HaveLiteralItself((WorldObjectItself<?>) target, Access.PRIVATE));
		
		// remove target from map
		worldMap.removeObject(target);
		
		// remove position from target
		targetState.removeLiterals(PositionLiteral.class);
	}
	
	@Override
	public String output() {
		return agent + " collected " + targets.get(0);
	}

	@Override
	public boolean supportMultiTargets() {
		return false;
	}

}
